package com.doit.demo.day02.transformations;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @DATE 2022/2/27/11:23
 * @Author MDK
 * @Version 2021.2.2
 *
 *      使用java8的lambda表达式完成map功能
 *
 **/
public class MapDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> lines = env.socketTextStream("linux01", 8888);

        //scala写法:  lines.map(e => e.toUpperCase())
        //           lines.map(_.toUpperCase)
        // SingleOutputStreamOperator<String> upperStream = lines.map(e -> e.toUpperCase());
        // SingleOutputStreamOperator<String> upperStream2 = lines.map(String::toUpperCase);

        MapFunction<String, String> mapFunction = new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return value.toUpperCase();
            }
        };

        SingleOutputStreamOperator<String> upperStream = lines.map(mapFunction);

        upperStream.print();

        env.execute();
    }
}
